﻿@{
    ViewBag.Title = T("Admin.Configuration.Measures.Dimensions").Text;
}

<div class="section-header">
    <div class="title">
        <i class="fas fa-ruler-combined"></i>
        <span>@T("Admin.Configuration.Measures.Dimensions")</span>
    </div>
</div>

<div>
	@(Html.Telerik().Grid<MeasureDimensionModel>()
        .Name("measure-dimension-grid")
        .DataKeys(x =>
        {
            x.Add(y => y.Id);
        })
        .Columns(columns =>
        {
            columns.Bound(x => x.Name)
                .Width(200);
            columns.Bound(x => x.SystemKeyword)
                .Width(150);
            columns.Bound(x => x.Ratio)
                .Format("{0:0.00000000}")
                .Width(180);
            columns.Bound(x => x.DisplayOrder)
                .Centered()
                .Width(100);
            columns.Bound(x => x.IsPrimaryDimension)
                .Width(100)
                .Centered()
                .ClientTemplate(Html.SymbolForBool("IsPrimaryDimension"));
            columns.Command(commands =>
            {
                commands.Custom("edit-measure-dimension").Text(T("Common.Edit"));
                commands.Delete().Localize(T);
            }).Width(180)
            .HtmlAttributes(new { align = "right", @class = "omega" });
        })
        .ToolBar(commands => commands.Template(DimensionGridCommands))
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
                .Select("Dimensions", "Measure")
                .Delete("DeleteDimension", "Measure");
        })
        .EnableCustomBinding(true))
</div>
    
@helper DimensionGridCommands(Grid<MeasureDimensionModel> grid)
{
	<button type="submit" id="btnAddNew" name="btnAddNew" class="btn" onclick="javascript:openPopup('@(Url.Action("CreateDimensionPopup", "Measure", new { btnId = "btnRefresh" }))'); return false;">
		<i class="fa fa-plus"></i>
		<span>@T("Admin.Configuration.Measures.Dimensions.AddDimension")</span>
	</button>
	<input type="submit" id="btnRefresh" name="btnRefresh" class="d-none" />
}

<script>
	$(function() {
		$('#btnRefresh').click(function () {
			$('#measure-dimension-grid').data('tGrid').ajaxRequest();
			return false;
		});

		$('#measure-dimension-grid').on('click', '.t-grid-edit-measure-dimension', function (e) {
			e.preventDefault();
			var tr = $(this).closest('tr');
			var id = $('#measure-dimension-grid').data('tGrid').dataItem(tr).Id;
			var href = "@Url.Content("~/Admin/Measure/EditDimensionPopup/")" + id + "?btnId=btnRefresh";
			
			openPopup(href);
			return false;
		});
	});
</script>
